<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var findBottomLeftValue = function (root) {
        //层序遍历获取最后一层的最左边节点的值
        function levelOrder(root) {
          let queue = [root]
          let res = []
          while (queue.length) {
            let len = queue.length
            res.push([])
            for (let i = 0; i < len; i++) {
              let node = queue.shift()
              res[res.length - 1].push(node.val)
              if (node.left) {
                queue.push(node.left)
              }
              if (node.right) {
                queue.push(node.right)
              }
            }
          }
          return res
        }
        let res = levelOrder(root)
        return res[res.length - 1][0]
      }
    </script>
  </body>
</html>
